package com.burst.reptile.framework.web.result;

import lombok.Data;

/**
 * 服务接口通用结构
 * @author wujin
 * @date: 2020年2月22日 上午11:12:20
 */
@Data
public class ServiceResult<T> {

	/**
	 * 处理结构是否成功
	 */
	private boolean success;
	
	/**
	 * 消息
	 */
	private String message;
	
	/**
	 * 结果数据
	 */
	private T result;

	public ServiceResult(boolean success) {
		this.success = success;
	}

	public ServiceResult(boolean success, String message) {
		this.success = success;
		this.message = message;
	}

	public ServiceResult(boolean success, String message, T result) {
		this.success = success;
		this.message = message;
		this.result = result;
	}

	public static <T> ServiceResult<T> success() {
		return new ServiceResult<>(true);
	}

	public static <T> ServiceResult<T> of(T result) {
		ServiceResult<T> serviceResult = new ServiceResult<>(true);
		serviceResult.setResult(result);
		return serviceResult;
	}
	
	public static <T> ServiceResult<T> error(String msg) {
		return new ServiceResult<>(false, msg);
	}

	public static <T> ServiceResult<T> notFound() {
		return new ServiceResult<>(false, Message.NOT_FOUND.getValue());
	}

	public enum Message {
		NOT_FOUND("Not Found Resource!"), NOT_LOGIN("User not login!");

		private String value;

		Message(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}
	}
}
